﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CarlowPitBoy
{
    public partial class TileMenu : Form
    {
        /// <summary>
        /// Makes form grab and moveable at any point
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0;//0x2;
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        /// </summary>

        //private Image dotAnimImage;//???

        private Point mousePos;
        private const int ActiveWidth = 800;
        private const int ActiveHeight = 980;

        private Button shellDeShellBtn;
        private Button shellBtn;
        private Button deShellBtn;

        private Button fileBrowseBtn;

        private Button terItemBrowseBtn;
        private Button mapObjectSave;
        private Button mapObjectSaveAs;
        
        private Graphics g;

        public TileMenu()
        {
            InitializeComponent();
            setupControls();
        }

        private void setupControls()
        {
            //stateChangeCbo.Text = "Map Properties";//fix
            xmlOpenFileDialog.InitialDirectory = "Map Objects";  // fix
            stateChangeCbo.Text = "Map Properties";

            checkForStateChange();
            updateState();
        }

        internal void generateButtons()
        {
            const int MENU_STRIP_HEIGHT = 23;
            const int BUTTON_X_LOCATION = 460;
            //const int BUTTON_Y_LOCATION = 93;
            //const int OFFSET_PER_BUTTON = 50;
            //int currentOffset = 0;

            shellBtn = new Button(Image.FromFile(@"Menu Objects\Shell.PNG"), Image.FromFile(@"Menu Objects\ShellPressed.PNG"), this.Width - MENU_STRIP_HEIGHT, 0);
            deShellBtn = new Button(Image.FromFile(@"Menu Objects\DeShell.PNG"), Image.FromFile(@"Menu Objects\DeShellPressed.PNG"), this.Width - MENU_STRIP_HEIGHT, 0);

            shellDeShellBtn = shellBtn;

            fileBrowseBtn = new Button(Image.FromFile(@"Menu Objects\Browse.PNG"), Image.FromFile(@"Menu Objects\BrowsePressed.PNG"), 513, 59);//???
            fileBrowseBtn.visible = false;

            terItemBrowseBtn = new Button(Image.FromFile(@"Menu Objects\Browse.PNG"), Image.FromFile(@"Menu Objects\BrowsePressed.PNG"), BUTTON_X_LOCATION, 193);
            terItemBrowseBtn.visible = false;

            mapObjectSave = new Button(Image.FromFile(@"Menu Objects\Save.PNG"), Image.FromFile(@"Menu Objects\SavePressed.PNG"), BUTTON_X_LOCATION, 243);
            mapObjectSave.visible = false;
            mapObjectSaveAs = new Button(Image.FromFile(@"Menu Objects\SaveAsPressed.PNG"), Image.FromFile(@"Menu Objects\SaveAsPressed.PNG"), BUTTON_X_LOCATION, 293);
            mapObjectSaveAs.visible = false;
        }



        private void TileMenu_Paint(object sender, PaintEventArgs e)
        {
            g = e.Graphics;
            if(shellDeShellBtn.visible)
                g.DrawImage(shellDeShellBtn.drawnImage, shellDeShellBtn.xPos, shellDeShellBtn.yPos);
            if(fileBrowseBtn.visible)
                g.DrawImage(fileBrowseBtn.drawnImage, fileBrowseBtn.xPos, fileBrowseBtn.yPos);
            if(mapObjectSave.visible)
                g.DrawImage(mapObjectSave.drawnImage, mapObjectSave.xPos, mapObjectSave.yPos);
            if(mapObjectSaveAs.visible)
                g.DrawImage(mapObjectSaveAs.drawnImage, mapObjectSaveAs.xPos, mapObjectSaveAs.yPos);
        }

        private void TileMenu_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                KeyReference.leftMouse.pressed();
                shellDeShellBtn.checkPressed(e.Location);
                fileBrowseBtn.checkPressed(e.Location);
                mapObjectSave.checkPressed(e.Location);
                mapObjectSaveAs.checkPressed(e.Location);
                checkForDrag();
            }
        }

        private void TileMenu_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                KeyReference.leftMouse.depressed();
                checkActiveButtons(e);
            }
        }

        private void TileMenu_MouseMove(object sender, MouseEventArgs e)
        {
            mousePos = e.Location;
        }

        private void checkActiveButtons(MouseEventArgs e)
        {
            if (shellDeShellBtn.checkActivated(e.Location))
            {
                if (shellDeShellBtn == shellBtn)
                {
                    shellDeShellBtn = deShellBtn;
                    this.Height = 23;
                }
                else
                {
                    shellDeShellBtn = shellBtn;
                    this.Height = ActiveHeight;
                }
            }
            else if (fileBrowseBtn.checkActivated(e.Location))
                xmlOpenFileDialog.ShowDialog();
            else if (mapObjectSave.checkActivated(e.Location))
            {
                //save current object depending on state
            }
            else if (mapObjectSaveAs.checkActivated(e.Location))
            {
                //save new object
            }
            
        }

        internal void buttonUpdate()
        {
            shellDeShellBtn.checkRepressed(mousePos, KeyReference.leftMouse);
            fileBrowseBtn.checkRepressed(mousePos, KeyReference.leftMouse);
            mapObjectSave.checkRepressed(mousePos, KeyReference.leftMouse);
            mapObjectSaveAs.checkRepressed(mousePos, KeyReference.leftMouse);
        }

        private void checkForDrag()
        {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }

        internal void updateWorld()
        {
            //checkForStateChange();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Browse for a .map.xml with the name "/num/ /num/ /mapname/"
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Save current map name's information or open save location chooser for user
            //If map coordinate changed then save new file and delete old one
            //save to folder "Iteration 1"
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Open save location chooser for user
            //If same coordinate used twice then messagebox user and put into a folder
            //"Iteration 2", 3, 4 etc.
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Options
        }

        private void animationEditorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Open animation editor form
        }

        private void stateChangeCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkForStateChange();
            updateState();
        }

        /// <summary>
        /// Check which state (Map Props, Terrain, Item or Editor) is selected and sets the state accordingly
        /// </summary>
        private void checkForStateChange()
        {
            if (stateChangeCbo.Text == "Map Properties")
                CurrentMap.state = 1;
            else if (stateChangeCbo.Text == "Terrain Editor")
                CurrentMap.state = 2;
            else if (stateChangeCbo.Text == "Item Editor")
                CurrentMap.state = 3;
            else if (stateChangeCbo.Text == "Character Editor")
                CurrentMap.state = 4;
            else
                MessageBox.Show("Error; IGNORE IF ON STARTUP, Misspelling in 'checkForStateChange method in TileMenu.cs.'");
        }

        /// <summary>
        /// Updates all the windows controls, images and displays based on the current state
        /// </summary>
        private void updateState()
        {
            if (CurrentMap.state == 1)
                showMapProperties();
            else if (CurrentMap.state == 2)
                showTerrainProperties();
            else if (CurrentMap.state == 3)
                showItemProperties();
            else if (CurrentMap.state == 4)
                showCharacterProperties();
            else
                MessageBox.Show("Error; Incorrect state selected, caused by 'stateChangeCbo_SelectedIndexChanged' method in 'TileMenu.cs'", "Error");
        }

        private void showMapProperties()
        {
            importantChk.Visible = false;
        }

        private void showTerrainProperties()
        {
            const string OBJECTS_LABEL_TEXT = "Terrain Properties";

            importantChk.Visible = true;
            fileBrowseBtn.visible = false;//custom button
            terItemBrowseBtn.visible = false;//custom button

            terObjectsCbo.Visible = true;
            terObjectsLbl.Visible = true;
            terObjectsLbl.Text = OBJECTS_LABEL_TEXT;

            terAnimationCbo.Visible = true;
            terAnimationLbl.Visible = true;

            terAreaDialogueChk.Visible = true;
            terAreaDialogueLbl.Visible = true;
            terAreaDialogueTxt.Visible = true;

            terCharAtSquareLbl.Visible = true;
            terCharAtSquareCharCbo.Visible = true;

            terCollidableCbo.Visible = true;
            terCollidableLbl.Visible = true;

            terExistsOnMapChk.Visible = true;
            terExistsOnMapLbl.Visible = true;

            terGivesItemCbo.Visible = true;
            terGivesItemChk.Visible = true;
            terGivesItemLbl.Visible = true;

            terInteractCharAtSquareChk.Visible = true;
            terInteractCharAtSquareLbl.Visible = true;
            terInteractCharAtSquareTxt.Visible = true;

            terInteractDialogueChk.Visible = true;
            terInteractDialogueLbl.Visible = true;
            terInteractDialogueTxt.Visible = true;

            terInteractItemAtSquareChk.Visible = true;
            terInteractItemAtSquareLbl.Visible = true;
            terInteractItemAtSquareTxt.Visible = true;

            terItemAtSquareLbl.Visible = true;
            terItemAtSquareItemCbo.Visible = true;


            terItemGetCharAtSquareCbo.Visible = true;
            terItemGetCharAtSquareChk.Visible = true;
            terItemGetCharAtSquareLbl.Visible = true;
            terItemGetCharAtSquareTxt.Visible = true;

            terItemGetDialogueCbo.Visible = true;
            terItemGetDialogueChk.Visible = true;
            terItemGetDialogueLbl.Visible = true;
            terItemGetDialogueTxt.Visible = true;


            terItemGetItemAtSquareCbo.Visible = true;
            terItemGetItemAtSquareChk.Visible = true;
            terItemGetItemAtSquareLbl.Visible = true;
            terItemGetItemAtSquareTxt.Visible = true;

            terItemGetNoteDialogueLbl.Visible = true;

            terLoadPointChk.Visible = true;
            terLoadPointLbl.Visible = true;

            terMagicStateChk.Visible = true;
            terMagicStateLbl.Visible = true;


            terMemActivateLbl.Visible = true;
            terMemAct1Lbl.Visible = true;
            terMemAct1MapCbo.Visible = true;
            terMemAct1MemCbo.Visible = true;
            terMemAct1ObjectCbo.Visible = true;

            terMemAct2Lbl.Visible = true;
            terMemAct2MapCbo.Visible = true;
            terMemAct2MemCbo.Visible = true;
            terMemAct2ObjectCbo.Visible = true;

            terMemAct3Lbl.Visible = true;
            terMemAct3MapCbo.Visible = true;
            terMemAct3MemCbo.Visible = true;
            terMemAct3ObjectCbo.Visible = true;

            terMemConLbl.Visible = true;
            terMemCon1Cbo.Visible = true;
            terMemCon1Choice1Cbo.Visible = true;
            terMemCon1Choice2Cbo.Visible = true;
            terMemCon1Choice3Txt.Visible = true;
            terMemCon1Choice4Txt.Visible = true;
            terMemCon1Lbl.Visible = true;

            terMemCon2Cbo.Visible = true;
            terMemCon2Choice1Cbo.Visible = true;
            terMemCon2Choice2Cbo.Visible = true;
            terMemCon2Choice3Txt.Visible = true;
            terMemCon2Choice4Txt.Visible = true;
            terMemCon2Lbl.Visible = true;

            terMemCon3Cbo.Visible = true;
            terMemCon3Choice1Cbo.Visible = true;
            terMemCon3Choice2Cbo.Visible = true;
            terMemCon3Choice3Txt.Visible = true;
            terMemCon3Choice4Txt.Visible = true;
            terMemCon3Lbl.Visible = true;

            terMemCon4Cbo.Visible = true;
            terMemCon4Choice1Cbo.Visible = true;
            terMemCon4Choice2Cbo.Visible = true;
            terMemCon4Choice3Txt.Visible = true;
            terMemCon4Choice4Txt.Visible = true;
            terMemCon4Lbl.Visible = true;

            terMemCon5Cbo.Visible = true;
            terMemCon5Choice1Cbo.Visible = true;
            terMemCon5Choice2Cbo.Visible = true;
            terMemCon5Choice3Txt.Visible = true;
            terMemCon5Choice4Txt.Visible = true;
            terMemCon5Lbl.Visible = true;

            terQuestRelatedCbo.Visible = true;
            terQuestRelatedLbl.Visible = true;

            terShowDialogueLbl.Visible = true;

            terSwapEffectCbo.Visible = true;
            terSwapSignCbo.Visible = true;
            terSwapsWhenLbl.Visible = true;
            terSwapValTxt.Visible = true;

            terTeleportsChk.Visible = true;
            terTeleportsLbl.Visible = true;
            terTelLoadPointCbo.Visible = true;
            terTelMapChooseCbo.Visible = true;

            loadTerrainMemorisedconditions();
        }

        private void loadTerrainMemorisedconditions()
        {
            //throw new NotImplementedException();
        }//showTerrainProperties

        private void showItemProperties()
        {
            importantChk.Visible = true;
            fileBrowseBtn.visible = true;
        }

        private void showCharacterProperties()
        {
            importantChk.Visible = true;
            fileBrowseBtn.visible = true;
        }

        private void mapMusicChk_CheckedChanged(object sender, EventArgs e)
        {
            if (mapMusicChk.Checked)
            {
                mapMusicTxt.Visible = true;
                mapMusicNoteLbl.Visible = true;
            }
            else
            {
                mapMusicTxt.Visible = false;
                mapMusicNoteLbl.Visible = false;
                
            }
        }

        //private void terAnimationCbo_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //Error check make sure has .anim in name
        //    //Read .anim.xml
        //}

        //private void terMemCon1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //Different options;
        //    //( None )
        //    //Change Location
        //    //Change Collidable
        //    //Change Dialogue
        //    //Change Item Given
        //    //Create Item at square (Gridsnap applies)
        //    //Create Character at square
        //    //Change Exists on Map
        //    //Use Magic on Object
        //    string[] possibleOptions = new string[8];
        //    possibleOptions[0] = "( None )";
        //    possibleOptions[1] = "Change Collidable";
        //    possibleOptions[2] = "Change Dialogue";
        //    possibleOptions[3] = "Change Item Given";
        //    possibleOptions[4] = "Create Item at square (Gridsnap applies)";
        //    possibleOptions[5] = "Create Character at square";
        //    possibleOptions[6] = "Change Exists on Map";
        //    possibleOptions[7] = "Use Magic on Object";

        //    if (terMemCon1Cbo.Text == possibleOptions[0])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[1])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[2])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[3])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[4])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[5])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[6])
        //    {
        //    }
        //    else if (terMemCon1Cbo.Text == possibleOptions[7])
        //    {
        //    }
        //    else
        //    {
        //        MessageBox.Show("Contact manufacturer. Invalid string in Combo Box. Error with terMemCon2Cbo Method. ", "Terrain Memory Condition Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        //    }
        //}

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            //error check for name already in list
            if (CurrentMap.state == 2)
                xmlOpenFileDialog.InitialDirectory = @"\Map Objects\Terrain";
            else if (CurrentMap.state == 3)
                xmlOpenFileDialog.InitialDirectory = @"\Map Objects\Items";
            else if (CurrentMap.state == 4)
                xmlOpenFileDialog.InitialDirectory = @"\Map Objects\Characters";
            else
                MessageBox.Show("Error : Contact Manufacturer. Incorrect state allowed to access browse button, check 'openFileDialog1_Ok' method in 'TileMenu.cs'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            terObjectsCbo.Items.Add(xmlOpenFileDialog.SafeFileName);
        }

        private void terObjectsCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (terObjectsCbo.Text == "( Browse )")
            {
                //check for name already in list
                xmlOpenFileDialog.RestoreDirectory = true;
                xmlOpenFileDialog.InitialDirectory = @"\Map Objects\Terrain";
                xmlOpenFileDialog.ShowDialog();                
            }
            else if (terObjectsCbo.Text.EndsWith(".ter.xml"))
            {
                //N.B Open file, read 
            }
            else
            {
                terObjectsCbo.Text = "";
                MessageBox.Show("Error : Please select a .ter.xml file. If you have, then this file may be corrupt.", "Error incorrect file selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void terAnimationCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            //open file dialog nonsense N.B
        }

        private void terCollidableCbo_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.collidable = terCollidableCbo.Checked;
        }

        private void terQuestRelatedCbo_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.questRelated = terQuestRelatedCbo.Checked;
        }

        private void terInteractDialogueChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueInteractBool = terInteractDialogueChk.Checked;
        }

        private void terInteractDialogueTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueInteractText = terInteractDialogueTxt.Text;
        }

        private void terAreaDialogueChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueAreaEnterBool = terAreaDialogueChk.Checked;
        }

        private void terAreaDialogueTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueAreaEnterText = terAreaDialogueTxt.Text;
        }

        private void terItemGetDialogueChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueItemReceiveBool = terItemGetDialogueChk.Checked;
        }

        private void terItemGetDialogueTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueItemReceiveText = terItemGetDialogueTxt.Text;
        }

        private void terItemGetDialogueCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.dialogueItemReceiveItem = terItemGetDialogueCbo.Text;
        }

        private void terGivesItemChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.giveItemBool = terGivesItemChk.Checked;
        }

        private void terGivesItemCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.giveItemItem = terGivesItemCbo.Text;
        }

        private void terItemAtSquareItemCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareItemCreated = terItemAtSquareItemCbo.Text;
        }

        private void terInteractItemAtSquareChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareInteractBool = terInteractItemAtSquareChk.Checked;
        }

        private void terInteractItemAtSquareTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareInteractText = terInteractItemAtSquareTxt.Text;
        }

        private void terItemGetItemAtSquareChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareItemReceiveBool = terItemGetItemAtSquareChk.Checked;
        }

        private void terItemGetItemAtSquareTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareItemReceiveText = terInteractItemAtSquareTxt.Text;
        }

        private void terItemGetItemAtSquareCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.itemSquareItemReceiveItem = terItemGetItemAtSquareCbo.Text;
        }

        private void terCharAtSquareCharCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareCharacterCreated = terCharAtSquareCharCbo.Text;
        }

        private void terInteractCharAtSquareChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareInteractBool = terInteractCharAtSquareChk.Checked;
        }

        private void terInteractCharAtSquareTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareInteractText = terInteractCharAtSquareTxt.Text;
        }

        private void terItemGetCharAtSquareChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareItemReceiveBool = terItemGetCharAtSquareChk.Checked;
        }

        private void terItemGetCharAtSquareTxt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareItemReceiveText = terItemGetCharAtSquareTxt.Text;
        }

        private void terItemGetCharAtSquareCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.characterSquareItemReceiveItem = terItemGetCharAtSquareCbo.Text;
        }

        private void terExistsOnMapChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.existsBool = terExistsOnMapChk.Checked;
        }

        private void terSwapEffectCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.existsMagicSwapper = terSwapEffectCbo.Text;
        }

        private void terSwapSignCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.existsGtLtEq = terSwapSignCbo.Text;
        }

        private void terSwapValTxt_TextChanged(object sender, EventArgs e)
        {
            try
            {
                CurrentMap.currentTerrain.existsSwapValue = Convert.ToInt32(terSwapValTxt);
            }
            catch(FormatException)
            {
                CurrentMap.currentTerrain.existsSwapValue = 0;
                terSwapValTxt.Text = "0";
                MessageBox.Show("Only whole numbers between 0 and 500 may be entered into this box", "Only whole numbers may be entered here", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        //( None )
        //Change Collidable
        //Change Dialogue
        //Change Item Given
        //Create Item at square (Gridsnap applies)
        //Create Character at square (Gridsnap applies)
        //Change Exists on Map
        //Use Magic on Object

        private void memCon1ChoiceUpdate()
        {
            terMemCon1Choice1Cbo.Items.Clear();
            terMemCon1Choice1Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice1(CurrentMap.currentTerrain.memorisedCondition1));

            terMemCon1Choice2Cbo.Items.Clear();
            terMemCon1Choice2Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice2(CurrentMap.currentTerrain.memorisedCondition1));

            terMemCon1Choice3Txt.Text = (CurrentMap.getMemoryConditionChoice3(CurrentMap.currentTerrain.memorisedCondition1));

            terMemCon1Choice4Txt.Text = (CurrentMap.getMemoryConditionChoice4(CurrentMap.currentTerrain.memorisedCondition1));
        }

        private void memCon2ChoiceUpdate()
        {
            terMemCon2Choice1Cbo.Items.Clear();
            terMemCon2Choice1Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice1(CurrentMap.currentTerrain.memorisedCondition2));

            terMemCon2Choice2Cbo.Items.Clear();
            terMemCon2Choice2Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice2(CurrentMap.currentTerrain.memorisedCondition2));

            terMemCon2Choice3Txt.Text = (CurrentMap.getMemoryConditionChoice3(CurrentMap.currentTerrain.memorisedCondition2));

            terMemCon2Choice4Txt.Text = (CurrentMap.getMemoryConditionChoice4(CurrentMap.currentTerrain.memorisedCondition2));
        }

        private void memCon3ChoiceUpdate()
        {
            terMemCon3Choice1Cbo.Items.Clear();
            terMemCon3Choice1Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice1(CurrentMap.currentTerrain.memorisedCondition3));

            terMemCon3Choice2Cbo.Items.Clear();
            terMemCon3Choice2Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice2(CurrentMap.currentTerrain.memorisedCondition3));

            terMemCon3Choice3Txt.Text = (CurrentMap.getMemoryConditionChoice3(CurrentMap.currentTerrain.memorisedCondition3));

            terMemCon3Choice4Txt.Text = (CurrentMap.getMemoryConditionChoice4(CurrentMap.currentTerrain.memorisedCondition3));
        }

        private void memCon4ChoiceUpdate()
        {
            terMemCon4Choice1Cbo.Items.Clear();
            terMemCon4Choice1Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice1(CurrentMap.currentTerrain.memorisedCondition4));

            terMemCon4Choice2Cbo.Items.Clear();
            terMemCon4Choice2Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice2(CurrentMap.currentTerrain.memorisedCondition4));

            terMemCon4Choice3Txt.Text = (CurrentMap.getMemoryConditionChoice3(CurrentMap.currentTerrain.memorisedCondition4));

            terMemCon4Choice4Txt.Text = (CurrentMap.getMemoryConditionChoice4(CurrentMap.currentTerrain.memorisedCondition4));
        }

        private void memCon5ChoiceUpdate()
        {
            terMemCon5Choice1Cbo.Items.Clear();
            terMemCon5Choice1Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice1(CurrentMap.currentTerrain.memorisedCondition5));

            terMemCon5Choice2Cbo.Items.Clear();
            terMemCon5Choice2Cbo.Items.AddRange(CurrentMap.getMemoryConditionChoice2(CurrentMap.currentTerrain.memorisedCondition5));

            terMemCon5Choice3Txt.Text = (CurrentMap.getMemoryConditionChoice3(CurrentMap.currentTerrain.memorisedCondition5));

            terMemCon5Choice4Txt.Text = (CurrentMap.getMemoryConditionChoice4(CurrentMap.currentTerrain.memorisedCondition5));
        }
        private void terLoadPointChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.loadPoint = terLoadPointChk.Checked;
        }

        private void terTeleportsChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.teleportsBool = terTeleportsChk.Checked;
        }

        private void terTelMapChooseCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.teleportsMap = terTelMapChooseCbo.Text;
        }

        private void terTelLoadPointCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.teleportsLoadPoint = terTelLoadPointCbo.Text;
        }

        private void terMagicStateChk_CheckedChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.rememberMagicState = terMagicStateChk.Checked;
        }

        private void terMemCon1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCondition1 = terMemCon1Cbo.Text;
            memCon1ChoiceUpdate();
        }

        private void terMemCon1Choice1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon1Choice1 = terMemCon1Choice1Cbo.Text;
        }

        private void terMemCon1Choice2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon1Choice2 = terMemCon1Choice2Cbo.Text;
        }

        private void terMemCon1Choice3Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon1Choice3 = terMemCon1Choice3Txt.Text;
        }

        private void terMemCon1Choice4Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon1Choice4 = terMemCon1Choice4Txt.Text;
        }

        private void terMemCon2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCondition2 = terMemCon2Cbo.Text;
            memCon2ChoiceUpdate();
        }

        private void terMemCon2Choice1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon2Choice1 = terMemCon2Choice1Cbo.Text;
        }

        private void terMemCon2Choice2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon2Choice2 = terMemCon2Choice2Cbo.Text;
        }

        private void terMemCon2Choice3Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon2Choice3 = terMemCon2Choice3Txt.Text;
        }

        private void terMemCon2Choice4Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon2Choice4 = terMemCon2Choice4Txt.Text;
        }

        private void terMemCon3Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCondition3 = terMemCon3Cbo.Text;
            memCon3ChoiceUpdate();
        }

        private void terMemCon3Choice1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon3Choice1 = terMemCon3Choice1Cbo.Text;
        }

        private void terMemCon3Choice2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon3Choice2 = terMemCon3Choice2Cbo.Text;
        }

        private void terMemCon3Choice3Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon3Choice3 = terMemCon3Choice3Txt.Text;
        }

        private void terMemCon3Choice4Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon3Choice4 = terMemCon3Choice4Txt.Text;
        }

        private void terMemCon4Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCondition4 = terMemCon4Cbo.Text;
            memCon4ChoiceUpdate();
        }

        private void terMemCon4Choice1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon4Choice1 = terMemCon4Choice1Cbo.Text;
        }

        private void terMemCon4Choice2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon4Choice2 = terMemCon4Choice2Cbo.Text;
        }

        private void terMemCon4Choice3Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon4Choice3 = terMemCon4Choice3Txt.Text;
        }

        private void terMemCon4Choice4Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon4Choice4 = terMemCon4Choice4Txt.Text;
        }

        private void terMemCon5Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCondition5 = terMemCon5Cbo.Text;
            memCon5ChoiceUpdate();
        }

        private void terMemCon5Choice1Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon5Choice1 = terMemCon5Choice1Cbo.Text;
        }

        private void terMemCon5Choice2Cbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon5Choice2 = terMemCon5Choice2Cbo.Text;
        }

        private void terMemCon5Choice3Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon5Choice3 = terMemCon5Choice3Txt.Text;
        }

        private void terMemCon5Choice4Txt_TextChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.memorisedCon5Choice4 = terMemCon5Choice4Txt.Text;
        }

        private void terMemAct1MapCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory1Map = terMemAct1MapCbo.Text;
        }

        private void terMemAct1ObjectCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory1Object = terMemAct1ObjectCbo.Text;
        }

        private void terMemAct1MemCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory1Memory = terMemAct1MemCbo.Text;
        }

        private void terMemAct2MapCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory2Map = terMemAct2MapCbo.Text;
        }

        private void terMemAct2ObjectCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory2Object = terMemAct2ObjectCbo.Text;
        }

        private void terMemAct2MemCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory2Memory = terMemAct2MemCbo.Text;
        }

        private void terMemAct3MapCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory3Map = terMemAct3MapCbo.Text;
        }

        private void terMemAct3ObjectCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory3Object = terMemAct3ObjectCbo.Text;
        }

        private void terMemAct3MemCbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMap.currentTerrain.activatesMemory3Memory = terMemAct3MemCbo.Text;
        }
    }
}
